<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="t_category" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 增加检测标准 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="产品类别" prop="">
              {{t_category.pro_name}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="范围类别" prop="tech_type">
              <el-select style='width:100%' v-model="t_category.tech_type">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in s_type" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检测标准名称" prop="tech_name">
              <el-input v-model="t_category.tech_name" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="引用标准文件" prop="">
              {{t_category.tech_fileid}}
              <el-button @click="popSelectionStandardFile('','tech_fileid')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="启用状态" prop="tech_state">
              <el-select style='width:100%' v-model="t_category.tech_state">
                <el-option label="启用" value="1" />
                <el-option label="禁用" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="technologyAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/mes/product/CartogramTechnology?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
    </el-form>
    <el-dialog :visible.sync="SelectionStandardFileVisible" append-to-body>
      <SelectionStandardFile v-if="SelectionStandardFileVisible" ref="SelectionStandardFile" :popparams="popparams"> </SelectionStandardFile>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SelectionStandardFile from "@/views/mes/product/SelectionStandardFile";
  export default {
    name: 'TechnologyAdd',
    components: {
      SelectionStandardFile,
    },
    props: ['popparams'],
    data() {
      return {
        SelectionStandardFileVisible: false,
        SelectionStandardFileValue: null,
        SelectionStandardFileDesc: null,
        vueparams: this.getVUEParams(""),
        t_category: {
          pro_name: null,
          tech_type: null,
          tech_name: null,
          tech_fileid: null,
          tech_state: null,
        },
        s_type: [],
        loading: false,
        rules: {
          tech_type: [{
            required: true,
            message: "范围类别不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/product/TechnologyAction/technologyAdd?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      technologyAddSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/product/TechnologyAction/technologyAddSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/product/CartogramTechnology/cartogramTechnology?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSelectionStandardFile(desc, value) {
        this.SelectionStandardFileVisible = true;
        this.SelectionStandardFileDesc = desc;
        this.SelectionStandardFileValue = value;
      },
      closeSelectionStandardFile(value, desc) {
        this.SelectionStandardFileVisible = false;
        this.$set(this.t_category, this.SelectionStandardFileDesc, desc);
        this.$set(this.t_category, this.SelectionStandardFileValue, value);
      },
    },
  }
</script>
